package com.kay.springbootRESTful.controller;

import com.kay.springbootRESTful.entity.Customer;
import com.kay.springbootRESTful.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Kay
 * @Date: 2019/12/12 15:45
 */
@RestController
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("save")
    @ResponseStatus(code = HttpStatus.CREATED)
    public Customer save(@RequestBody Customer customer) {
        return customerService.save(customer);
    }

    @PutMapping("update")
    public ResponseEntity<Customer> update(@RequestBody Customer newCustomer) {
        return customerService.update(newCustomer);
    }

    @GetMapping("findById")
    public Customer findById(Integer customerId) {
        return customerService.findById(customerId);
    }

    @GetMapping("findAll")
    public Page<Customer> findAll(Pageable pageable) {
        return customerService.findAll(pageable);
    }

    @DeleteMapping("delete")
    public ResponseEntity<?> delete(Integer customerId) {
        return customerService.delete(customerId);
    }

}
